package com.pickgliss.loaders
{
	import com.pickgliss.utils.StringUtils;
	
	import flash.net.URLVariables;

	public class LoaderManager
	{
		public function LoaderManager()
		{
		}

		private static var _instance:LoaderManager;

		public static function get Instance():LoaderManager
		{
			if (_instance == null)
			{
				_instance=new LoaderManager();
			}
			return _instance;
		}

		/**
		 * 重写后的loaderManager 一定要用起来足够简单，方便
		 * @param url
		 * @param callback
		 * @param args
		 * @param compressed
		 *
		 */
		public function loadEasy(url:String, callback:Function=null, args:URLVariables=null, compressed:Boolean=false):void
		{
			var ext:String=StringUtils.getFileExtendtionFromUrl(url);
			var loader:BaseLoader;
			switch (ext)
			{
				case "png":
					if (PngxLoader.isPngxURL(url))
					{
						loader=new PngxLoader(url, callback);
					}
					else
					{
						loader=new BitmapLoader(url, callback);
					}
					break;
				case "jpg":
				case "jpeg":
				case "gif":
					loader=new BitmapLoader(url, callback);
					break;
				case "swf":
					loader= new SwfLoader(url,callback);
					break;
				case "txt":
				case "aspx":
				case "ashx":
				case "html":
					loader= new TextLoader(url,callback);
					break;
				default:
					loader=new BaseLoader(url, callback);
			}
			loader.loadFromWeb();
		}
	}
}
